package com.hn.springcloud.controller;

import com.hn.springcloud.pojo.User;
import com.hn.springcloud.service.UserService;
import com.hn.springcloud.vo.ResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * hanni
 * 2019/2/14 0014
 * 16:42
 */
@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private UserService userService;

    @GetMapping("/list")
    public List<User> userList(){
        List<User> userList = userService.findUsers();

        return userList;
    }


    @PostMapping
    public ResponseVo add1(User user){
        return  userService.add1(user);
    }

    //@RequestParam()括号中的参数名称必须和后台保持一致
    @PostMapping("/a")
    public ResponseVo add2(@RequestParam("id") Integer uid, @RequestParam("uname") String name){
        return  userService.add2(uid,name);
    }


    @GetMapping("/b")
    public List<User> get(){
        return userService.get();
    }

    @GetMapping("/c")
    public List<User> get(User u){
        return userService.get(u);
    }

    @GetMapping("/d")                                      //与后台参数不一致的展示
    public List<User> get(@RequestParam("id") Integer uid, @RequestParam("uname") String name){
        return userService.get(uid,name);
    }

    //占位符传参
    @DeleteMapping("/e/{id}/xxx/{name}")
    public ResponseVo delete(@PathVariable("id") Integer uid,@PathVariable("name") String uname){
        return userService.delete(uid,uname);
    }








}
